 // 创建用户集合
// 引入mongoose第三方模块
const mongoose = require('mongoose');
//引入string-random
const stringRandom = require("string-random");

// 创建用户集合规则
const bookSchema = new mongoose.Schema({
    ISBN:{
        type: String,
        required: true,
        unique:true
    },
    title:{
        type: String
    },
    author:{
        type:String
    },
    publisher:{
        type: String
    },
    pubdate:{
        type: String
    },
    //版次
    edition:{
        type:String
    },
    page:{
        type: String
    },
    price:{
        type: String
    },
    //内容简介
    gist:{
        type: String
    },
    img:{
        type: String
    },
    //开本
    format:{
        type: String
    },
    //装帧
    binding:{
        type: String
    },
    firstCategory:{
        type: String
    },
    secondCategory:{
        type: Array
    }
});

// 创建集合
const Book = mongoose.model('Book', bookSchema);
async function createBook () {
	const book = await Book.create({
        ISBN: "9787111644521", 
        title: "Flutter实战",
        author: "杜文",
        publisher: "机械工业出版社",
        pubdate: "2020-01",
        edition: "1",
        page: 451,
        price: "99.00",
        //内容简介
        gist: "Flutter中文网社区创始人倾力撰写的网红书《Flutter实战》",
        img: "http://www.kfzimg.com/sw/kfzimg/1839/01685a417216704946_n.jpg",
        //开本
        format: "其它",
        //装帧
        binding: "平装",
        firstCategory: "互联网",
        secondCategory: ["编程与开发"]
	});
}

//createBook();


// 将用户集合做为模块成员进行导出
module.exports = {
   Book
}; 